<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/4/12 0012
 * Time: 12:36
 */

namespace app\author\controller;

use think\facade\Session;
use think\Controller;

class Login extends Controller
{
    public function login(){
        return view("login");
    }
    public function doLogin(){
        if(request()->post()){
            $param = request()->param();
            $member = db("member")->where('mobile',$param['val1'])->find();
            if($member['is_author'] != 1){
                return ['state' => -3,'msg' => '状态不正确'];
            }
            if(!captcha_check($param['val3'])){
                return ['state' => -2,'msg' => '验证码不正确'];
            }
            if($member['password'] != md5($param['val2'])){
                return ['state' => -1,'msg' => '账号或密码不正确'];
            }
            session('author_member_id',$member['id']);
            return ['state' => 200,'msg' => 'SUCCESS'];
        }
    }
    public function logout(){
        Session::clear();
//        $this->error('退出成功','/author/login/login');
        $this->redirect('/author/login/login');
    }
}